package com.b2bpsssm.service.impl;

import com.b2bpsssm.common.R;
import com.b2bpsssm.mapper.AccountMapper;
import com.b2bpsssm.pojo.Account;
import com.b2bpsssm.service.AccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AccountServiceImpl implements AccountService {

    @Autowired
    private AccountMapper accountMapper;

    @Override
    public R queryAccountByPageLimit(Integer currentPage, Integer pageSize) {
        R r = new R();
        Integer start = (currentPage - 1) * pageSize;//分页第一个参数
        Integer off = pageSize; //分页第二个参数

//        System.out.println(start);
//        System.out.println(off);

        //查询后的数据
        List<Account> list = accountMapper.queryAccountByPageLimit(start, off);

        //成功后返回的结果
        r.setCode(200);
        r.setMassage("success");
        r.setData(list);
        return r;

    }

//新增
    @Override
    public R addAccount(Account account) {
        R r = new R();
        int result = accountMapper.addAccount(account);
        if (result>0){
            r.setCode(200);
            r.setMassage("success");
        }
        return r;
    }

    @Override
    public R updateAccount(Account account) {
        R r = new R();
        int result = accountMapper.updateAccount(account);
        if (result>0){
            r.setCode(200);
            r.setMassage("success");
        }
        return r;
    }

    @Override
    public R delAccount(Account account) {
        R r = new R();
        int result = accountMapper.delAccount(account);
        if (result>0){
            r.setCode(200);
            r.setMassage("success");
        }
        return r;
    }

    @Override
    public R disabledAccount(Account account) {
        R r = new R();
        int result = accountMapper.disabledAccount(account);
        if (result>0){
            r.setCode(200);
            r.setMassage("success");
        }
        return r;
    }

    @Override
    public R selAccountLikeName(Integer currentPage, Integer pageSize, String acc_Name) {
        R r = new R();
        Integer start = (currentPage - 1) * pageSize;//分页第一个参数
        Integer off = pageSize; //分页第二个参数

//        System.out.println(start);
//        System.out.println(off);

        //查询后的数据
        List<Account> list = accountMapper.selAccountLikeName(start, off,acc_Name);

        //成功后返回的结果
        r.setCode(200);
        r.setMassage("success");
        r.setData(list);
        return r;

    }
}
